package kg.aibek.projecteuler.p10;

public class Problem45 {
	public void solve() {
		long i = 286;
		while (true) {
			long number = i * (i + 1) / 2;
			if (isPentagonal(number) && isHexagonal(number)) {
				System.out.println(number);
				System.out.println(i);
				break;
			}
			i++;
			if (i > 100000000) {
				System.out.println("no sol");
				break;
			}
		}
	}

	private boolean isPentagonal(long number) {
		int a = (int) Math.sqrt((double) number * 2 / 3);
		a--;
		boolean b0 = number == (long) a * (3 * a - 1) / 2;
		a++;
		boolean b1 = number == (long) a * (3 * a - 1) / 2;
		a++;
		boolean b2 = number == (long) a * (3 * a - 1) / 2;
		a++;
		boolean b3 = number == (long) a * (3 * a - 1) / 2;

		return b0 || b1 || b2 || b3;
	}

	private boolean isHexagonal(long number) {
		int a = (int) Math.sqrt((double) number / 2);
		a--;
		boolean b0 = number == (long) a * (2 * a - 1);
		a++;
		boolean b1 = number == (long) a * (2 * a - 1);
		a++;
		boolean b2 = number == (long) a * (2 * a - 1);
		a++;
		boolean b3 = number == (long) a * (2 * a - 1);

		return b0 || b1 || b2 || b3;
	}

	public static void main(String[] args) {
		Problem45 p = new Problem45();
		p.solve();
		// System.out.println(p.isPentagonal(92));
	}
}
